Avoid destroying windows after they are unmapped
authorPo Lu <luangruo@yahoo.com>
Thu, 4 Apr 2024 01:53:07 +0000 (09:53 +0800)
committerPo Lu <luangruo@yahoo.com>
Thu, 4 Apr 2024 01:53:07 +0000 (09:53 +0800)
* java/org/gnu/emacs/EmacsActivity.java (destroy): Detach from
current window before calling finish.

* java/org/gnu/emacs/EmacsWindow.java (reparentTo): Don't clear
attachment state here...

* java/org/gnu/emacs/EmacsWindowManager.java (detachWindow):
...but do so here instead.

java/org/gnu/emacs/EmacsActivity.java
java/org/gnu/emacs/EmacsWindow.java
java/org/gnu/emacs/EmacsWindowManager.java

index a939641a75297db10a292b171c21bc0461fe3165..28bb6e4c065367381d8d21b647755e349c83ce84 100644 (file)
@@ -207,6 +207,18 @@ public class EmacsActivity extends Activity
   public final void
   destroy ()
   {
+    if (window != null)
+      {
+       /* Clear the window's pointer to this activity and remove the
+          window's view.  */
+       window.setConsumer (null);
+
+       /* The window can't be iconified any longer.  */
+       window.noticeDeiconified ();
+       layout.removeView (window.view);
+       window = null;
+      }
+
     finish ();
   }
 
index b085614de23146439fa3f4e0724625d3268140c7..91e97fa8b61d426109cabc92ac645745ef189015 100644 (file)
@@ -1322,10 +1322,6 @@ public final class EmacsWindow extends EmacsHandleObject
          manager = EmacsWindowManager.MANAGER;
          manager.detachWindow (EmacsWindow.this);
 
-         /* Reset window management state.  */
-         previouslyAttached = false;
-         attachmentToken = 0;
-
          /* Also unparent this view.  */
 
          /* If the window manager is set, use that instead.  */
index 21df77587b0c95d1f84613fdb8a9775951db14ad..a239fdc8ac2e97241917916d85ac9c40983cd320 100644 (file)
@@ -238,15 +238,19 @@ public final class EmacsWindowManager
   {
     WindowConsumer consumer;
 
-    if (window.getAttachedConsumer () != null)
-      {
-       consumer = window.getAttachedConsumer ();
+    /* Reset window management state.  */
+    window.previouslyAttached = false;
+    window.attachmentToken = 0;
+
+    /* Remove WINDOW from the list of active windows.  */
+    windows.remove (window);
 
+    if ((consumer = window.getAttachedConsumer ()) != null)
+      {
        consumers.remove (consumer);
        consumer.destroy ();
       }
 
-    windows.remove (window);
     pruneWindows ();
   }